package com.wanggsx.library.util;

import com.wanggsx.library.base.app.init.AppConstant;
import com.wanggsx.library.constant.ConstantSP;

import java.util.Set;

public class UtilsSPLogin {
    //实例
    private static final UtilsSP spIntance = UtilsSP.getInstance(AppConstant.folderName.replace("/",""));

    public static String getImageQidongye() {
        return spIntance.getString(ConstantSP.IMAGE_QIDONGYE);
    }

    public static String getLinkQidongye() {
        return spIntance.getString(ConstantSP.LINK_QIDONGYE);
    }

    public static String getUserId() {
        return spIntance.getString(ConstantSP.USER_ID);
    }

    public static String getUserName() {
        return spIntance.getString(ConstantSP.USER_NAME);
    }

    public static String getUserToken() {
        return spIntance.getString(ConstantSP.USER_TOTEN);
    }

    public static String getKeywords() {
        return spIntance.getString(ConstantSP.USER_KEY_WORDS);
    }

    public static String getWXnickname() {
        return spIntance.getString(ConstantSP.nickname);
    }

    public static String getWXsex() {
        return spIntance.getString(ConstantSP.sex);
    }

    public static String getWXunionid() {
        return spIntance.getString(ConstantSP.unionid);
    }

    public static String getWXheadimgurl() {
        return spIntance.getString(ConstantSP.headimgurl);
    }

    public static String getWXprivilege() {
        return spIntance.getString(ConstantSP.privilege);
    }

    public static String getWXprovince() {
        return spIntance.getString(ConstantSP.province);
    }

    public static String getWXcity() {
        return spIntance.getString(ConstantSP.city);
    }

    public static String getWXcountry() {
        return spIntance.getString(ConstantSP.country);
    }

    public static String getLongtitude() {
        return spIntance.getString(ConstantSP.USER_LON);
    }

    public static String getLatitude() {
        return spIntance.getString(ConstantSP.USER_LAT);
    }

    public static String getUserCache() {
        return spIntance.getString(ConstantSP.KEY_USER_CACHE);
    }

    public static String getIsFirst() {
        return spIntance.getString(ConstantSP.KEY_IS_FIRST);
    }

    public static String getRongcloud_token() {
        return spIntance.getString(ConstantSP.RONGCLOUD_TOKEN);
    }

    public static String getUser_nickname() {
        return spIntance.getString(ConstantSP.USER_NICKNAME);
    }

    public static String getUser_logo() {
        return spIntance.getString(ConstantSP.USER_LOGO);
    }

    public static String getUserImageHead(){
        return spIntance.getString(ConstantSP.headimgurl);
    }

    public static String getUser_level() {
        return spIntance.getString(ConstantSP.USER_LEVEL);
    }

    public static String getHistorySearch() {
        return spIntance.getString(ConstantSP.SEARCH_HISTORY);
    }

    public static String getSearchText() {
        return spIntance.getString(ConstantSP.SEARCH_TEXT);
    }

    public static boolean getIsNotVip(){
        if (getUser_level().equals("0")) {
            return true;
        }
        return false;
    }

    public static String getIsSignIn() {
        return spIntance.getString(ConstantSP.IS_SIGN_IN);
    }

    /**
     * 清理用户信息
     *
     * @return
     */
    public static void clearUser() {
        spIntance.remove(ConstantSP.USER_ID);
        spIntance.remove(ConstantSP.USER_TOTEN);
        spIntance.remove(ConstantSP.nickname);
        spIntance.remove(ConstantSP.sex);
        spIntance.remove(ConstantSP.headimgurl);
        spIntance.remove(ConstantSP.privilege);
        spIntance.remove(ConstantSP.province);
        spIntance.remove(ConstantSP.city);
        spIntance.remove(ConstantSP.country);
        spIntance.remove(ConstantSP.RONGCLOUD_TOKEN);
        spIntance.remove(ConstantSP.USER_NICKNAME);
        spIntance.remove(ConstantSP.USER_LOGO);
        spIntance.remove(ConstantSP.USER_LEVEL);
        spIntance.remove(ConstantSP.USER_LON);
        spIntance.remove(ConstantSP.USER_LAT);
        spIntance.remove(ConstantSP.KEY_USER_CACHE);
        spIntance.remove(ConstantSP.USER_KEY_WORDS);
        spIntance.remove(ConstantSP.USER_NAME);
    }

    /**
     * 存储数据
     *
     * @param strkey
     * @param obj
     */
    public static void putSP(String strkey, Object obj) {
        if (obj instanceof String) {
            spIntance.put(strkey, (String) obj,true);
        } else if (obj instanceof Integer) {
            spIntance.put(strkey, (Integer) obj,true);
        } else if (obj instanceof Long) {
            spIntance.put(strkey, (Long) obj,true);
        } else if (obj instanceof Float) {
            spIntance.put(strkey, (Float) obj,true);
        } else if (obj instanceof Set) {
            spIntance.put(strkey, (Set) obj,true);
        }
    }
}
